<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>思途CMS3.0</title>
 {template 'stourtravel/public/public_js'}
   {php echo Common::getCss('style.css,base.css,base2.css,plist.css,base_new.css'); }
   {php echo Common::getCss('ext-theme-neptune-all-debug.css','js/extjs/resources/ext-theme-neptune/'); }
    
   {php echo Common::getScript("uploadify/jquery.uploadify.min.js,jquery.buttonbox.js,choose.js"); }
   {php echo Common::getCss('uploadify.css','js/uploadify/'); }
</head>
<body style="overflow:hidden">
<table class="content-tab">
   <tr>
    <td width="119px" class="content-lt-td"  valign="top">
     {template 'stourtravel/public/leftnav'}
    <!--右侧内容区-->
    </td>
    <td valign="top" class="content-rt-td" style="overflow:hidden">
		<div class="cfg-header-bar clearfix">
			<span class="select-box w150 mt-5 ml-10 fl">
				<select name="isfrozen" onchange="goSearch(this)" class="select">
                    <option value="">产品类型</option>
                </select>
			</span>
			<span class="select-box w150 mt-5 ml-10 fl">
				<select name="status" onchange="goSearch(this)" class="select">
                    <option value="">结算状态</option>
                </select>
			</span>	
			
			<div class="cfg-header-search">
				<input type="text" id="searchkey" value="" datadef="订单号" class="search-text">
                <a href="javascript:;" class="search-btn" onclick="CHOOSE.searchKeyword()">搜索</a>
			</div>		
			<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
		</div>	

 		<div id="product_grid_panel" class="content-nrt">
    
  		</div>
  </td>
  </tr>
 </table> 
<script>


  Ext.onReady(
    function() 
    {
		 Ext.tip.QuickTipManager.init();

        $(".btnbox").buttonBox();

        $("#searchkey").focusEffect();


		
		
		//产品store
        window.product_store=Ext.create('Ext.data.Store',{

		 fields:[
             'id',
             'nickname',
             'consumeamount',
             'account',
             'subnum',
             'subordernum',
             'money',
             'money_frozen',
             'fxjointime',
             'status',
             'verifytime',
             'isfrozen',
             'rankname',
             'ordersn',
             'addtime',
             'productname',
             'platform_income',
             'commission1',
             'commission2',
             'commission3',
             'commission',
             'member_name',
             'member1_name',
             'member2_name',
             'member3_name'


         ],
         proxy:{
		   type:'ajax',
		   api: {
              read: SITEURL+'fenxiao/admin/finance/index/action/read',  //读取数据的URL
			  update:SITEURL+'fenxiao/admin/fenxiao/index/action/save',
			  destroy:SITEURL+'fenxiao/admin/fenxiao/index/action/delete'
              },
		      reader:{
                type: 'json',   //获取数据的格式 
                root: 'lists',
                totalProperty: 'total'
                }	
	         },
		 remoteSort:true,	 
		 pageSize:30,	 	
         autoLoad:true,
		 listeners:{
             load:function( store, records, successful, eOpts )
             {
                 if(!successful){
                     ST.Util.showMsg("{__('norightmsg')}",5,1000);
                 }
                 var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                 $("#line_page").html(pageHtml);
                 window.product_grid.doLayout();
                 $(".pageContainer .pagePart a").click(function () {
                     var page = $(this).attr('page');
                     product_store.loadPage(page);
                 });

             }
		 }
		  
       });
	   
	  //产品列表 
	  window.product_grid=Ext.create('Ext.grid.Panel',{ 
	   store:product_store,
	   renderTo:'product_grid_panel',
	   border:0,
	   bodyBorder:0,
	   bodyStyle:'border-width:0px',
	   scroll:'vertical',
	   bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "没有数据了",
					items:[
                        {
                            xtype:'panel',
                            id:'listPagePanel',
                            html:'<div id="line_page"></div>'
                       },
					  {
						  xtype:'combo',
						  fieldLabel:'每页显示数量',
						  width:170,
						  labelAlign:'right',
						  forceSelection:true,
						  value:30,
						  store:{fields:['num'],data:[{num:30},{num:60},{num:100}]},
						  displayField:'num',
						  valueField:'num',
						  listeners:{
							  select:CHOOSE.changeNum
						  }
					  }
					
					],
				  listeners: {
						single: true,
						render: function(bar) {
							var items = this.items;
                            bar.insert(0,Ext.create('Ext.toolbar.Fill'));
						}
					}	
                 }), 		 			 
	   columns:[
           {
               text:'创建时间',
               width:'10%',
               dataIndex:'addtime',
               align:'center',
               menuDisabled:true,
               border:0,
               sortable:false,
               renderer : function(value, metadata,record) {
                   return value;
               }
           },
               {
                   text:'订单号',
                   width:'10%',
                   dataIndex:'ordersn',
                   align:'center',
                   menuDisabled:true,
                   border:0,
                   sortable:false,
                   renderer : function(value, metadata,record) {
                       return value;
                   }
               },

           {
               text:'类型：产品名称',
               width:'7%',
               dataIndex:'productname',
               align:'center',
               menuDisabled:true,
               sortable:false,
               renderer : function(value, metadata,record,rowIndex,colIndex) {
                   return value;
               }
           },
           {
               text:'平台收入',
               width:'8%',
               dataIndex:'platform_income',
               align:'center',
               sortable:false,
               menuDisabled:true,
               renderer : function(value, metadata,record,rowIndex,colIndex) {
                   return value;
               }
           },

               {
                   text:'一级分销商佣金',
                   width:'8%',
                   dataIndex:'commission1',
                   align:'center',
                   sortable:false,
                   menuDisabled:true,
                   renderer : function(value, metadata,record,rowIndex,colIndex) {
                      return value;
                   }
               },
               {
                   text:'二级分销商佣金',
                   width:'8%',
                   dataIndex:'commission2',
                   align:'center',
                   sortable:false,
                   menuDisabled:true,
                   renderer : function(value, metadata,record,rowIndex,colIndex) {
                       return value;
                   }
               },
               {
                   text:'三级分销商佣金',
                   width:'8%',
                   dataIndex:'commission3',
                   align:'center',
                   sortable:false,
                   menuDisabled:true,
                   renderer : function(value, metadata,record,rowIndex,colIndex) {
                       return value;
                   }
               },
               {
                   text:'自购佣金',
                   width:'8%',
                   dataIndex:'commission',
                   align:'center',
                   sortable:false,
                   menuDisabled:true,
                   renderer : function(value, metadata,record,rowIndex,colIndex) {
                       return value;
                   }
               },
			   {
				  text:'一级分销商',
				  width:'12%',
				  dataIndex:'member1_name',
				  align:'center',
                  sortable:false,
                  menuDisabled:true
			   },
               {
                   text:'二级分销商',
                   width:'12%',
                   dataIndex:'member2_name',
                   align:'center',
                   sortable:false,
                   menuDisabled:true
               },
               {
                   text:'三级分销商',
                   width:'12%',
                   dataIndex:'member3_name',
                   align:'center',
                   sortable:false,
                   menuDisabled:true
               },
               {
                   text:'自购分销商',
                   width:'12%',
                   dataIndex:'member_name',
                   align:'center',
                   sortable:false,
                   menuDisabled:true
               },
               {
                   text:'结算状态',
                   width:'7%',
                   dataIndex:'status',
                   align:'center',
                   menuDisabled:true,
                   renderer : function(value, metadata,record,rowIndex,colIndex) {
                      return value==5?'已结算':'未结算';
                   }
               }

             ],
			 listeners:{
		            boxready:function()
		            {
                        var height=Ext.dom.Element.getViewportHeight();
					   this.maxHeight=height-106;
					   this.doLayout();
		            },
					afterlayout:function(grid)
					{

						window.product_store.each(function(record){
				         id=record.get('id');


					   });
					   
					   var data_height=0;
					   try{
					     data_height=grid.getView().getEl().down('.x-grid-table').getHeight();
					   }catch(e)
					   {

					   }
					  var height=Ext.dom.Element.getViewportHeight();
					// console.log(data_height+'---'+height);
					  if(data_height>height-106)
					  {
						  window.has_biged=true;
						  grid.height=height-106;
					  }
					  else if(data_height<height-106)
					  {
						  if(window.has_biged)
						  {
							//delete window.product_grid.height;
							window.has_biged=false;  
							grid.doLayout();
						  }
					  }
				  }
			 },
			 plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                  clicksToEdit:2,
                  listeners:{
					 edit:function(editor, e)
					 {
						   var id=e.record.get('id');
						 //  var view_el=window.product_grid.getView().getEl();
						 // view_el.scrollBy(0,this.scroll_top,false);
						updateField(0,id,e.field,e.value,0);
						return false;
						  
					 },
					 beforeedit:function(editor,e)
					 {

						// var view_el=window.product_grid.getView().getEl();
	                     //this.scroll_top=view_el.getScrollTop();				   
	 
					 }
				 }
               })
             ],
			viewConfig:{
				//enableTextSelection:true
				}	   
	   });
	   
	  
	  
	})
	
	//实现动态窗口大小
  Ext.EventManager.onWindowResize(function(){ 
       var height=Ext.dom.Element.getViewportHeight(); 
	   var data_height=window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
	   if(data_height>height-106)
	     window.product_grid.height=(height-106);
	   else
	      delete window.product_grid.height;
	   window.product_grid.doLayout();
	   
	 }) 
	

  

 
  //更新套餐的字段，并显示相应的text框，仅用于租车的支付方式
  function updateMixField(ele,id,field,value,type)
  {
	  if(type=='select')
	  {
		  var val=Ext.get(ele).getValue();
		 if(val==2)
		  Ext.get(ele).parent('table').down('input').show();
		 else
		  Ext.get(ele).parent('table').down('input').hide();  
	  }
	  updateField(ele,id,field,value,type);
  }


  
  //更新某个字段
  function updateField(ele,id,field,value,type,callback)
  {
	  var record=window.product_store.getById(id.toString());
	  if(type=='select'||type=='input')
	  {
		  value=Ext.get(ele).getValue();
	  }
	  var view_el=window.product_grid.getView().getEl();
	
	 
	  Ext.Ajax.request({
						 url   :  "list/action/update",
						 method  :  "POST",
						 datatype  :  "JSON",
						 params:{id:id,field:field,val:value,kindid:window.product_kindid},
						 success  :  function(response, opts) 
						 {
							 if(response.responseText=='ok')
							 {
							//  var view_el=window.product_grid.getView().getEl()
	                          //   var scroll_top=view_el.getScrollTop();				   
					   
							   record.set(field,value);
							   record.commit();
                               if(typeof(callback)=='function')
                                  callback(record);
						      // view_el.scrollBy(0,scroll_top,false);
							 }
                             else
                             {
                                 ST.Utils.showMsg("{__('norightmsg')}",5,1000);
                             }
						 }});

  }
  
  
  //删除套餐
  function delSuit(id)
  {
  }

   //去搜索
   function goSearch(ele)
   {
       var name=$(ele).attr('name');
       var val=$(ele).val();
       window.product_store.getProxy().setExtraParam(name, val);
       window.product_store.loadPage(1);
   }


 
</script>

</body>
</html>
